<?php

//	Author: 	Christos Polydorou
//	Email:		std04237@di.uoa.gr
//	Purpose: 	Register new user

require_once ("../DB/connection.php");
require_once ("../DB/defines.php");
require_once ("../Frameworks/Objects/user.php");

function DB_registerUser($user)
{

    global $conn;

    // The name of the stored procedure
    $sp_name = "usp_registeruser";

    // The return variable
    $retval;

    // Get values
    $username = $user->GetUsername();
    $password = $user->GetPassword();
    $email = $user->GetEmail();
	$fname = $user->GetName();
	$lname = $user->GetSurName();

    // Create a new statement
    $stmt = mssql_init($sp_name, $conn);

    // Bind values
    mssql_bind($stmt, "RETVAL", $retval, SQLINT4, true, false, 1);
    mssql_bind($stmt, '@username', $username, SQLVARCHAR, false, false, 50);
    mssql_bind($stmt, '@password', $password, SQLVARCHAR, false, false, 50);
    mssql_bind($stmt, '@email', $email, SQLVARCHAR, false, false, 50);
    mssql_bind($stmt, '@fname', $fname, SQLVARCHAR, false, false, 50);
    mssql_bind($stmt, '@lname', $lname, SQLVARCHAR, false, false, 50);

    // Execute the statement
	error_reporting(0);
    $status = mssql_execute($stmt);
    if ($status)
        return DB_OK;
    else
        return DB_ERROR_REGISTER;
}

?>